﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.Common;
using PMS.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using BusinessFacade;
using EntityManage;

public partial class Modules_Personal_MyMessageDetail : System.Web.UI.Page
{
    IOther_MessageHandler msgHandler = new Other_MessageManage();
    IOther_MessageReceverHandler msgRecvHandler = new Other_MessageReceverManage();
    ISys_UserHandler userHandler = new Sys_UserManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dataBind();
        }
    }

    private void dataBind()
    {
        if (Request["ID"] != null && Request["ID"] != string.Empty)
        {
            int ID = 0;
            int.TryParse(Request["ID"], out ID);

            if (ID != 0)
            {
                try
                {
                    Other_MessageQuery msgQuery = msgHandler.GetOther_MessageQuery(ID);
                    if (msgQuery != null)
                    {
                        Sys_UserQuery userQuery = userHandler.GetSys_UserQuery(msgQuery.User_ID);
                        lblUser.Text = userQuery.Name;
                        lblTitle.Text = msgQuery.Title;
                        lblDate.Text = msgQuery.Create_Time.ToString();
                        lblContent.InnerHtml = msgQuery.Content;

                        Other_MessageReceverQuery[] recvList = msgRecvHandler.GetOther_MessageReceverQueryList(" Message_ID = @Message_ID", new SqlParameter[]{new SqlParameter("@Message_ID", ID)});
                        if (recvList != null && recvList.Length > 0)
                        {
                            string recv = "";
                            int userId = int.Parse(Session["CurrentUserID"].ToString());
                            foreach (Other_MessageReceverQuery recvQuery in recvList)
                            {
                                Sys_UserQuery uq = userHandler.GetSys_UserQuery(recvQuery.User_ID);
                                if (uq != null)
                                    recv = recv + uq.Name + ",";

                                if (userId == uq.ID)
                                {
                                    recvQuery.Status = 1;
                                    msgRecvHandler.UpdateOther_MessageRecever(recvQuery);
                                }
                            }
                            recv = recv.Length > 0 ? recv.Substring(0, recv.Length - 1) : recv;
                            lblRecever.Text = recv;
                        }
                    }
                }
                catch
                {
                    Jscript.Alert("操作失败!", this.Page);
                }
            }
        }
    }

}
